//
//  BaseTableViewController.swift
//  SinaWeibo
//
//  Created by mac on 15/12/14.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController , VisitorLoginViewDelegate {
    //判断用户是否登录
     var userlogin = UserAccountViewModel().userLogin
    //新建属性访客视图
    var visitorLoginView: VisitorLoginView?
    
    override func loadView() {
        if userlogin {
            super.loadView()
        }else{
            setVisitorLoginView()
        }

    }
    private func setVisitorLoginView(){
          visitorLoginView = VisitorLoginView()
        //v.backgroundColor = UIColor.redColor()
        //设置代理
        visitorLoginView?.visitroViewDelegate = self
        view = visitorLoginView
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "userWillLogin")
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "userWillRegister")
      
    }
    
    func userWillLogin() {
        print(__FUNCTION__)
        //添加到 导航视图控制器

        let oath = OAuthViewController()
        let nav = UINavigationController(rootViewController: oath)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    func userWillRegister() {
        let oauth = OAuthViewController()
        //oauth.delegate = self
        //添加到 导航视图控制器
        let nav = UINavigationController(rootViewController: oauth)
        presentViewController(nav, animated: true, completion: nil)
    }

    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

   
   
}
